//
//  TopicView.m
//  A段项目,漫画
//
//  Created by dlios on 15-4-22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "TopicView.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface TopicView ()
@end

@implementation TopicView
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.selectedTopArr = [NSMutableArray array];
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTopView];
    
}

#pragma mark 创建视图
-(void)creatTopView
{
    self.topicTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    self.topicTableView.rowHeight = HEIGHT / 3;
    self.topicTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.topicTableView];
    [_topicTableView release];
    
    self.topicTableView.delegate = self;
    self.topicTableView.dataSource = self;
}




#pragma mark 实现两个协议方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        static NSString *reuse = @"reuse";
        TopicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[TopicViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
        }
        cell.labelTop.text = [self.selectedTopArr[0] topic_title];
//        cell.labelTow.text = [self.selectedTopArr[1] topic_title];
//        cell.labelThree.text = [self.selectedTopArr[2] topic_title];
        
        NSURL *url = [NSURL URLWithString:[self.selectedTopArr[indexPath.row]topic_url]];
        [cell.topicView sd_setImageWithURL:url];
        return cell;
        
    }else if (indexPath.row == 1){
        static NSString *reuse = @"reuse";
        TopicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[TopicViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
        }
//        cell.labelOne.text = [self.selectedTopArr[0] topic_title];
        cell.labelTop.text = [self.selectedTopArr[1] topic_title];
//        cell.labelThree.text = [self.selectedTopArr[2] topic_title];
        NSURL *url = [NSURL URLWithString:[self.selectedTopArr[indexPath.row]topic_url]];
        [cell.topicView sd_setImageWithURL:url];
        return cell;
        
    }else if (indexPath.row == 2){
        static NSString *reuse = @"reuse";
        TopicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[TopicViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuse];
        }
        
//        cell.labelOne.text = [self.selectedTopArr[0] topic_title];
//        cell.labelTow.text = [self.selectedTopArr[1] topic_title];
        cell.labelTop.text = [self.selectedTopArr[2] topic_title];
        NSURL *url = [NSURL URLWithString:[self.selectedTopArr[indexPath.row]topic_url]];
        [cell.topicView sd_setImageWithURL:url];
        return cell;
    }else{
        static NSString *reuse = @"reuse";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        return cell;
    }
    
//    static NSString *reuse = @"reuse";
//    TopicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
//    if (cell == nil) {
//        cell = [[[TopicViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
//    }
//    cell.labelOne.text = [self.selectedTopArr[0] topic_title];
////    cell.labelTow.text = [self.selectedTopArr[1] topic_title];
////    cell.labelThree.text = [self.selectedTopArr[2] topic_title];
//    
//    NSURL *url = [NSURL URLWithString:[self.selectedTopArr[indexPath.row]topic_url]];
//    [cell.topicView sd_setImageWithURL:url];
//    return cell;
}


#pragma mark 点击cell跳转到每周漫发现
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TopicSlowFinderViewController *tsfvc = [[TopicSlowFinderViewController alloc]init];
//    Topic *p = self.selectedTopArr[indexPath.row];
//    tsfvc.special_event_url = p.special_event_url;
    [self.navigationController pushViewController:tsfvc animated:YES];
    [tsfvc release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
